//
//  WelcomePageViewController.m
//  OrderSeat
//
//  Created by 王威 on 13-12-29.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "WelcomePageViewController.h"
#import "MyTapGestureRecognizer.h"

@interface WelcomePageViewController ()

@end

@implementation WelcomePageViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setPageImages];
}


- (void)setPageImages
{
    CGRect frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    
    NSArray *images = @[@"start1.png",@"start2.png",@"start3.png"];
    if (ScreenHeight > 480) {
        images = @[@"start1-568h@2x.png",@"start2-568h@2x.png",@"start3-568h@2x.png"];
    }
    
    NSInteger count = 0;
    NSInteger pagesCount = 3;
    for (NSString *image in images) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:image];
        imageView.left = count * imageView.width;
        
        MyTapGestureRecognizer *singleTap = [[MyTapGestureRecognizer alloc]initWithTarget:self action:@selector(imageTapAction:)];
        [singleTap setTag:count];
        [imageView addGestureRecognizer:singleTap];
        
        [_theScrollview addSubview:imageView];
        count++;
    }
    
    _theScrollview.contentWidth = _theScrollview.width*pagesCount;
    _pageControl.currentPage = 0;
    _pageControl.numberOfPages = pagesCount;
}

- (void)imageTapAction:(id)sender
{
    if ([sender tag] == 2) {
        [AppDelegate sharedInstance].window.rootViewController = [AppDelegate sharedInstance].tabBarController;
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGPoint offset = scrollView.contentOffset;
    CGRect bounds = scrollView.frame;
    [_pageControl setCurrentPage:offset.x/bounds.size.width];
}



@end
